Strong magnetic fields play a crucial role in the removal of angular momentum from collapsing clouds and protostellar discs and are necessary for the formation of disc winds as well as jets from the inner disc and indeed, strong large-scale poloidal magnetic fields are observed in protostellar discs at all radii down to $\sim 10 R_\odot$. Nevertheless, by the time the star is visible virtually all of the original magnetic flux has vanished. I explore mechanisms for removing this flux during the formation of the protostar once it is magnetically disconnected from the parent cloud, looking at both radiative and convective protostars. This includes a numerical investigation of buoyant magnetic field removal from convective stars. It is found that if the star goes through a fully convective phase all remaining flux can easily be removed from the protostar, essentially on an Alfv\'en timescale. If on the other hand the protostar has no fully convective phase then some flux can be retained, the quantity depending on the net magnetic helicity, which is probably quite small. Only some fraction of this flux is visible at the stellar surface. I also look at how the same mechanisms could prevent flux from accreting onto the star at all, meaning that mass would only accrete as fast as it is able to slip past the flux.